<template>
  <div class="DrawCards">
    <el-card>
      <div class="shearch">
        <el-input placeholder="请输入ID" v-model="id" clearable>
          <template slot="prepend">用户ID</template>
        </el-input>
        <el-input placeholder="请输入手机号" v-model="phone" clearable>
          <template slot="prepend">手机号</template>
        </el-input>
        <el-button icon="el-icon-search" class="btn" @click="search"
          >搜索</el-button
        >
      </div>
      <div class="type">
        <el-radio-group
          v-model="type"
          size="medium"
          fill="#39383d"
          @change="search"
        >
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button label="2">推荐中</el-radio-button>
          <el-radio-button label="1">已屏蔽</el-radio-button>
        </el-radio-group>
        已推荐：{{ recommendNum }}<i style="margin-left: 20px"></i> 已屏蔽：{{
          screenNum
        }}
      </div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="user_id" label="用户ID"> </el-table-column>
        <el-table-column prop="nickname" label="用户昵称"> </el-table-column>
        <el-table-column prop="avatar" label="卡片页面">
          <template slot-scope="scope">
            <el-image
              class="img"
              style="width: 80px; height: 100px"
              :src="scope.row.avatar"
              :preview-src-list="[scope.row.avatar]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="downTime" label="状态">
          <template slot-scope="scope">
            {{ scope.row.status == 0 ? "已屏蔽" : "正常" }}
          </template>
        </el-table-column>
        <el-table-column prop="recommend" label="是否推荐">
          <template slot-scope="scope">
            {{ scope.row.is_recommend == 0 ? "未推荐" : "已推荐" }}
          </template>
        </el-table-column>
        <el-table-column prop="address" label="处理">
          <template slot-scope="scope">
            <el-button
              type="info"
              size="small"
              @click="setStatus(scope.row.user_id, scope.row.status)"
              plain
              >{{ scope.row.status == 0 ? "取消屏蔽" : "屏蔽" }}</el-button
            >
            <el-button
              type="success"
              size="small"
              @click="setRecommend(scope.row.user_id, scope.row.is_recommend)"
              plain
              >{{
                scope.row.is_recommend == 0 ? "推荐" : "取消推荐"
              }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // 分页
import {
  matchList,
  matchSetStatus,
  matchSetRecommend,
} from "@/api/operationManagement";
export default {
  components: { Pagination },
  data() {
    return {
      id: "",
      phone: "",
      type: "",
      tableData: [],
      recommendNum: "",
      screenNum: "",
      total: 0,
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    async getList() {
      const res = await matchList({
        type: this.type,
        user_id: this.id,
        mobile: this.mobile,
        page: this.page,
        pageSize: this.pageSize,
      });
      if (res.code == 0) {
        this.total = res.data.total;
        this.tableData = res.data.list;
        this.screenNum = res.data.screenNum;
        this.recommendNum = res.data.recommendNum;
      }
    },
    search() {
      this.page = 1;
      this.getList();
    },
    //设置卡片状态
    async setStatus(user_id, nowStatus) {
      const res = await matchSetStatus({
        user_id,
        status: nowStatus == 0 ? "1" : "0",
      });
      if (res.code == 0) {
        this.$message({
          type: "success",
          message: "操作成功！",
        });
        this.getList();
      }
    },
    //推荐卡片
    async setRecommend(user_id, type) {
      const res = await matchSetRecommend({
        user_id,
        recommend: type == 0 ? "1" : "0",
      });
      if (res.code == 0) {
        this.$message({
          type: "success",
          message: "操作成功！",
        });
        this.getList();
      }
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style lang="less" scoped>
.DrawCards {
  padding: 20px;
  .shearch {
    .el-input {
      width: 300px;
      margin-right: 20px;
    }
  }
  .type {
    margin: 20px 0;
    .el-radio-group {
      margin-right: 20px;
    }
  }
}
</style>